package 腾讯;

import java.util.Scanner;

/**
 * @author zhangmin
 * @create 2022-04-24 19:59
 */
public class Main3 {
    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt();
        cin.nextLine();
        String line = cin.nextLine();
        char[] sbs=line.toCharArray();
        //从左到右记录进攻的战斗力，从右向左记录防守的战斗力
        long[] ws=new long[n],vs=new long[n];
        ws[0]=sbs[0]=='0'?1:0;
        for (int i = 1; i < n; i++) {
            if (sbs[i]=='0'){
                ws[i]=ws[i-1]+(i+1);
            }else {
                ws[i]=ws[i-1];
            }
        }
        vs[n-1]=sbs[n-1]=='1'?n:0;
        for (int i = n-2; i >=0; i--) {
            if (sbs[i]=='1'){
                vs[i]=vs[i+1]+(i+1);
            }else {
                vs[i]=vs[i+1];
            }
        }
        long res=Math.min(Math.abs(0-vs[0]),Math.abs(ws[n-1]-0));
        for (int i = 1; i < n-1; i++) {
            long sum= Math.abs(ws[i]-vs[i+1]);
            res=Math.min(res,sum);
        }
        System.out.println(res);
    }

}
